<?php

// This function adds a filter to a search of discussions, so that
// only inactive discussions by users with the auto-hide 'permission'
// are fetched.
function AutoHide_AlterDiscussionSearch($DiscussionManager){
   $RoleIDs = ModerationList::$RoleIDs;
   $FirstRoleID = array_shift($RoleIDs);
   $SearchQuery = $DiscussionManager->DelegateParameters['SqlBuilder'];
   $SearchQuery->AddWhere('t','Active','','0','=','and');
   if (count($RoleIDs) > 0){
      $SearchQuery->AddWhere('u','RoleID','',$FirstRoleID,'=','and','','1','1');
      foreach ($RoleIDs as $RoleID){
         $SearchQuery->AddWhere('u','RoleID','',$RoleID,'=','or');
      }
      $SearchQuery->EndWhereGroup();
   }
   else{
      $SearchQuery->AddWhere('u','RoleID','',$FirstRoleID,'=','and');
   }
}

$Context->AddToDelegate('DiscussionManager','PostGetDiscussionBuilder',
	'AutoHide_AlterDiscussionSearch');

?>
